package test1;

import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入L和R，中间用空格隔开：");
        int L = sc.nextInt();
        int R = sc.nextInt();
        int count = 0;
        for (int i = L; i <= R; i++) {
            count += statistics(i);
        }
        System.out.println(count);
    }

    //写一个方法，判断一个数中有几个2
    public static int statistics(int x){
        int count = 0;
        while (x > 0){
            if (x % 10 == 2){
                count++;
            }
            x = x / 10;
        }
        return count;
    }
}
